﻿using UnityEngine;
using UnityEngine.EventSystems;

namespace Assets.AnimationPlayer.Scripts.Util
{
    public class YioksTriggerListener :EventTrigger
    {
        public delegate void VoidDelegate(GameObject go);
        public VoidDelegate OnClick;
        public VoidDelegate OnDown;
        public VoidDelegate OnEnter;
        public VoidDelegate OnExit;
        public VoidDelegate OnUp;
        public VoidDelegate OnSelected;
        public VoidDelegate OnUpdateSelect;

        public delegate void VoidDragDelegate(GameObject go, PointerEventData eventData);
        public VoidDragDelegate OnDragBegin;
        public VoidDragDelegate OnDraging;
        public VoidDragDelegate OnDragEnd;

        public static  YioksTriggerListener Get(GameObject go)
        {
            YioksTriggerListener listener = go.GetComponent<YioksTriggerListener>();
            if (listener == null) listener = go.AddComponent<YioksTriggerListener>();
            return listener;
        }

        public static  YioksTriggerListener Get(Transform go)
        {
            YioksTriggerListener listener = go.gameObject.GetComponent<YioksTriggerListener>();
            if (listener == null) listener = go.gameObject.AddComponent<YioksTriggerListener>();
            return listener;
        }

        public override void OnPointerClick(PointerEventData eventData)
        {
            if (OnClick != null) OnClick(gameObject);
        }
        public override void OnPointerDown(PointerEventData eventData)
        {
            if (OnDown != null) OnDown(gameObject);
        }
        public override void OnPointerEnter(PointerEventData eventData)
        {
            if (OnEnter != null) OnEnter(gameObject);
        }
        public override void OnPointerExit(PointerEventData eventData)
        {
            if (OnExit != null) OnExit(gameObject);
        }
        public override void OnPointerUp(PointerEventData eventData)
        {
            if (OnUp != null) OnUp(gameObject);
        }
        public override void OnSelect(BaseEventData eventData)
        {
            if (OnSelected != null) OnSelected(gameObject);
        }
        public override void OnUpdateSelected(BaseEventData eventData)
        {
            if (OnUpdateSelect != null) OnUpdateSelect(gameObject);
        }

        public override void OnBeginDrag(PointerEventData eventData)
        {
            if (OnDragBegin != null) OnDragBegin(gameObject, eventData);
        }
        public override void OnDrag(PointerEventData eventData)
        {
            if (OnDragBegin != null) OnDraging(gameObject, eventData);
        }
        public override void OnEndDrag(PointerEventData eventData)
        {
            if (OnDragBegin != null) OnDragEnd(gameObject, eventData);
        }
    }
}